package cn.syx.service.impl;

import cn.syx.dao.AccountDao;
import cn.syx.domain.Account;
import cn.syx.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service("accountService")
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    @Override
    public void save(Account account) throws IOException {

        accountDao.save(account);
    }

    @Override
    public List<Account> findAll() throws IOException {

        List<Account> accountList = accountDao.findAll();
        return accountList;
    }

    @Override
    public void updateAccount(Account account) {
        accountDao.updateAccount(account);
    }

    @Override
    public void deleteById(int id) {
        accountDao.deleteById(id);
    }

    @Override
    public void transfer(String outMan, double money, String inMan) {
        Account outAccount = new Account();
        outAccount.setName(outMan);
        outAccount.setMoney(money);
        accountDao.out(outAccount);

//        int i = 1 / 0;

        Account inAccount = new Account();
        inAccount.setName(inMan);
        inAccount.setMoney(money);
        accountDao.in(inAccount);

    }


}
